package guiLayer;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import net.miginfocom.swing.MigLayout;

public class ItemTab2 extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTable itemTable;

	/**
	 * Create the panel.
	 */
	public ItemTab2() {
		setLayout(new MigLayout("center", "[900px]", "[grow][40px]"));
		
		JPanel listPanel = new JPanel();
		listPanel.setBorder(new TitledBorder(null, "Vare liste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(listPanel, "cell 0 0,grow");
		listPanel.setLayout(new MigLayout("", "[grow][860px][grow]", "[5px][400px,grow]"));
		
		JScrollPane itemListScroll = new JScrollPane();
		itemListScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		itemListScroll.setAutoscrolls(true);
		listPanel.add(itemListScroll, "cell 1 1,grow");
		
		itemTable = new JTable();
		itemTable.setSurrendersFocusOnKeystroke(true);
		itemTable.setIntercellSpacing(new Dimension(10, 1));
		itemTable.setAutoCreateRowSorter(true);
		itemTable.setInheritsPopupMenu(true);
		itemTable.setRowHeight(22);
		itemTable.setShowVerticalLines(false);
		itemTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		itemTable.setFillsViewportHeight(true);
		itemTable.setModel(new DefaultTableModel(
			new Object[][] {
				{new Integer(712), "Test", "Test", "Produkt", Boolean.FALSE},
				{null, null, null, null, null},
				{null, null, null, null, null},
			},
			new String[] {
				"Vare nr.", "Navn", "Beskrivelse", "Vare type", "Prissat"
			}
		) {
			Class[] columnTypes = new Class[] {
				Integer.class, String.class, String.class, Object.class, Boolean.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		itemTable.getColumnModel().getColumn(0).setResizable(false);
		itemTable.getColumnModel().getColumn(0).setMinWidth(75);
		itemTable.getColumnModel().getColumn(0).setMaxWidth(75);
		itemTable.getColumnModel().getColumn(1).setResizable(false);
		itemTable.getColumnModel().getColumn(1).setPreferredWidth(100);
		itemTable.getColumnModel().getColumn(1).setMinWidth(100);
		itemTable.getColumnModel().getColumn(1).setMaxWidth(250);
		itemTable.getColumnModel().getColumn(2).setResizable(false);
		itemTable.getColumnModel().getColumn(2).setPreferredWidth(150);
		itemTable.getColumnModel().getColumn(2).setMinWidth(100);
		itemTable.getColumnModel().getColumn(2).setMaxWidth(300);
		itemTable.getColumnModel().getColumn(3).setResizable(false);
		itemTable.getColumnModel().getColumn(3).setPreferredWidth(100);
		itemTable.getColumnModel().getColumn(3).setMinWidth(100);
		itemTable.getColumnModel().getColumn(3).setMaxWidth(100);
		itemTable.getColumnModel().getColumn(4).setResizable(false);
		itemTable.getColumnModel().getColumn(4).setMinWidth(75);
		itemTable.getColumnModel().getColumn(4).setMaxWidth(75);
		itemListScroll.setViewportView(itemTable);
		
		JPopupMenu popupMenu = new JPopupMenu();
		addPopup(itemTable, popupMenu);
		
		JMenuItem menuItem = new JMenuItem("Se vare egenskaber");
		popupMenu.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("S\u00E6t salgspris");
		popupMenu.add(menuItem_1);
		
		JMenuItem menuItem_2 = new JMenuItem("Rediger vare");
		popupMenu.add(menuItem_2);
		
		JMenuItem menuItem_3 = new JMenuItem("Slet vare");
		popupMenu.add(menuItem_3);
		
		JPanel buttomPanel = new JPanel();
		add(buttomPanel, "cell 0 1,alignx trailing,growy");
		buttomPanel.setLayout(new MigLayout("", "[100px][100px]", "[25px]"));
		
		JButton btnUdskriv = new JButton("Udskriv");
		buttomPanel.add(btnUdskriv, "cell 0 0,grow");
		
		JButton btnNulstilFilter = new JButton("Nulstil filter");
		buttomPanel.add(btnNulstilFilter, "cell 1 0,grow");

	}

	private static void addPopup(Component component, final JPopupMenu popup) {
	}
}
